package com.yyw.rabbitmq.core.core;

import com.yyw.rabbitmq.api.Message;
import com.yyw.rabbitmq.core.config.AsyncConfig;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 消息发送的具体实现类
 */
@Component
public class RabbitBrokerImpl implements RabbitBroker{

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public void sendQuick(Message message) {
        // 使用异步队列发送消息
        AsyncConfig.submit(() -> {
            CorrelationData correlationData = new CorrelationData(String.format("%s#%s",
                    message.getMessageId(), System.currentTimeMillis()));
            rabbitTemplate.convertAndSend(message.getTopic(), message.getRouteKey(),
                    message,correlationData);
        });
    }

    @Override
    public void sendConfirm(Message message) {

    }

    @Override
    public void sendReliable(Message message) {

    }
}
